package com.atguigu.gmall.item.service.impl;

import com.atguigu.entity.BaseCategoryView;
import com.atguigu.entity.SkuImage;
import com.atguigu.entity.SkuInfo;
import com.atguigu.gmall.frign.product.ProductApiClient;
import com.atguigu.gmall.item.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class ItemServiceImpl implements ItemService {
    //远程调用接口
    @Autowired
    ProductApiClient productApiClient;
    @Override
    public Map<String, Object> getBySkuId(Long skuId) {
        Map<String,Object> map = new HashMap<>();
        SkuInfo skuInfo = productApiClient.getSkuInfo(skuId);
        //商品详情所需要的商品信息
        map.put("skuInfo",skuInfo);
        //商品所需要的分类信息
        BaseCategoryView baseCategoryView = productApiClient.getBaseCategoryView(skuInfo.getCategory3Id());
        map.put("Category3Id",baseCategoryView);
        //价格查询 需要单独查 不去缓存查
        BigDecimal price = productApiClient.getPrice(skuId);
        map.put("price",price);
        //查询库存的图片信息
        List<SkuImage> skuImage = productApiClient.getSkuImage(skuId);
        map.put("skuImage",skuImage);
        //查询根据spuInfo获取sku的排列
        Map skuValueIdsMap = productApiClient.getSkuValueIdsMap(skuInfo.getSpuId());
        map.put("map",skuValueIdsMap);
        return map;
    }
}
